import React from 'react'
import PropTypes from 'prop-types'
import { Card, WhiteSpace, WingBlank } from 'antd-mobile'
import { withRouter } from 'react-router-dom'

@withRouter
class Usercard extends React.Component {
  static propTypes = {
    userList: PropTypes.array.isRequired
  }
  handleClick (v) {
    this.props.history.push(`/chat/${v._id}`)
  }
  render () {
    return (
      <WingBlank>
        <WhiteSpace />
        {this.props.userList.map(v => (
          v.avatar ? <Card key={v._id} onClick={() => this.handleClick(v)}>
            <Card.Header title={v.user} thumb={require(`../../assets/image/${v.avatar}.png`)} extra={<span>{v.title}</span>} />
            <Card.Body>{v.desc.split('\n').map((v, i) => <p className='desc-p' key={i}>{v}</p>)}</Card.Body>
            {v.type === 'boss' ? (
              <Card.Footer content={'公司：' + v.company} extra={<div>薪资：{v.money}</div>}/>
            ) : null}
          </Card> : null
        ))}
      </WingBlank>
    )
  }
}

export default Usercard